//
//  CXLTwoTableViewCell.m
//  WYNews
//
//  Created by 夜猫子 on 2017/3/19.
//  Copyright © 2017年 夜猫子. All rights reserved.
//

#import "CXLTwoTableViewCell.h"
#import "CZAdditions.h"

@interface CXLTwoTableViewCell ()

@property (nonatomic, weak) UILabel *titleLabel;

@property (nonatomic, weak) UIImageView *imgsrcImage;

@property (nonatomic, weak) UILabel *replyCountLable;

@property (nonatomic, weak) UILabel *sourceLable;


@end

@implementation CXLTwoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    CGFloat margin = 10;
    
    UIImageView *imgsrcImage = [[UIImageView alloc]init];
    [self.contentView addSubview:imgsrcImage];
    
    UILabel *titleLabel = [UILabel cz_labelWithText:@"标题" fontSize:17 color:[UIColor blackColor]];
    [self.contentView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    titleLabel.numberOfLines = 0;
    
    UILabel *sourceLable = [UILabel cz_labelWithText:@"新闻来源" fontSize:14 color:[UIColor lightGrayColor]];
    [self.contentView addSubview:sourceLable];
    
    UILabel *replyCountLable = [UILabel cz_labelWithText:@"回复数" fontSize:14 color:[UIColor lightGrayColor]];
    [self.contentView addSubview:replyCountLable];
    
    [imgsrcImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView).offset(margin);
        make.bottom.equalTo(self.contentView).offset(-margin);
        make.size.mas_equalTo(CGSizeMake(102, 88));
    }];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imgsrcImage.mas_right).offset(margin);
        make.top.equalTo(imgsrcImage.mas_top);
        make.right.equalTo(self.contentView).offset(-margin);
    }];
    
    [sourceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView).offset(-margin);
        make.left.equalTo(imgsrcImage.mas_right).offset(margin);
    }];
    
    [replyCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sourceLable.mas_top);
        make.right.equalTo(self.contentView).offset(-margin);
    }];
    
    
    _imgsrcImage = imgsrcImage;
    _titleLabel = titleLabel;
    _sourceLable = sourceLable;
    _replyCountLable = replyCountLable;
}


- (void)setModel:(CXLNewListModel *)model {
    _model = model;
    
    [_imgsrcImage sd_setImageWithURL:[NSURL URLWithString:_model.imgsrc]];
    _titleLabel.text = _model.title;
    _sourceLable.text = _model.source;
    _replyCountLable.text = _model.replyCount;
}

@end

